<div th:fragment="jsfHeader">

    <meta charset="UTF-8">
    <div class="main-nav">
        <div class="container">
        </div>
    </div>

    <div class="top-bar">
        <div class="container">
            <div class="dflx sbt aic">
                <div class="left aic">
                    <img src="/images/suhu.png" width="50px" height="50px">
                    <a href="" class="logo"></a>
                    <span class="welcome c333 f14">欢迎访问速虎回收管理系统</span>
                </div>
                <div class="right f14 c333">
					<span class="dropdown">
                        <a href="" class="dropdown-toggle profile" data-toggle="dropdown" aria-expanded="false"> <div id="roleName_username"></div> <i class="md  md-keyboard-arrow-down"></i></a>
                        <ul class="dropdown-menu">
                            <li><a href="/user/logout"><i class="ti-power-off m-r-5"></i> 退出</a></li>
                        </ul>
                    </span>
                    <a href="###" class="ml15">账户设置</a>
                </div>
            </div>
        </div>
    </div>


    <script type="text/javascript">

        var contentPath = '';

//        window.onload = getCurrentUserInfo;

        //获取当前登录用户信息
        function getCurrentUserInfo() {

            $.ajax({
                url: contentPath + "/sso/userInfo",
                dataType: "json",
                data:{},
                type:"GET",
                success: function (response) {
                    console.log(response);
                    if(response && response.code===1000) {
                        $("#roleName_username").html("<b>"+response.data.buName+"-"+response.data.userName+"</b>");

                    }else {
                        alert(response.message);
                    }

                },
                error: function () {
                    alert("获取当前用户信息失败");
                }
            });
            //优化方案
            // const userInfo = sessionStorage.getItem("userInfo");
            // if(!userInfo) {
            //     console.log("当前session里没有用户信息，需要去后台获取用户信息");
            //     $.ajax({
            //         url:"/sso/userInfo",
            //         dataType: "json",
            //         data:{},
            //         type:"GET",
            //         success: function (response) {
            //             console.log(response);
            //             if(response && response.code===1000) {
            //                 sessionStorage.setItem("userInfo",JSON.stringify(response.data));//放进sessionStorage里面
            //             }else {
            //                 alert(response.message);
            //             }
            //
            //         },
            //         error: function () {
            //             alert("获取当前用户信息失败");
            //         }
            //     });
            // }else {
            //     console.log("当前session里已经含用户信息，无需调用后台用户信息接口");
            // }

        }

    </script>
</div>





